package com.xhxi.photobooker.controller;


import com.xhxi.photobooker.entity.PhotographerPackage;
import com.xhxi.photobooker.result.Result;
import com.xhxi.photobooker.service.PhotographerPackageService;
import com.xhxi.photobooker.service.PhotographerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/photo/photographer/package")
public class PhotographerPackageController {

    @Autowired
    private PhotographerPackageService packageService;
    @Autowired
    private PhotographerService photographerService;

    // 获取摄影师所有套餐
    @GetMapping("/list/{photographerId}")
    public Result<List<PhotographerPackage>> list(@PathVariable Long photographerId) {
        return Result.success(packageService.listByPhotographerId(photographerId));
    }

    // 新增套餐
    @PostMapping("/add")
    public Result<PhotographerPackage> add(@RequestBody PhotographerPackage pkg) {
        return Result.success(packageService.save(pkg));
    }

    // 修改套餐
    @PutMapping("/update")
    public Result<PhotographerPackage> update(@RequestBody PhotographerPackage pkg) {
        return Result.success(packageService.update(pkg));
    }

    // 删除套餐
    @DeleteMapping("/delete/{id}/{photographerId}")
    public Result<?> delete(@PathVariable Long id, @PathVariable Long photographerId) {
        return packageService.delete(id, photographerId) ? Result.success() : Result.error("删除失败");
    }

    // 设为默认套餐
    @PostMapping("/set-default/{id}/{photographerId}")
    public Result<?> setDefault(@PathVariable Long id, @PathVariable Long photographerId) {
        return packageService.setDefault(id, photographerId) ? Result.success() : Result.error("设置失败");
    }
}
